Calling a Stored Procedure
You call stored procedures using a Command object. When you issue a command on a stored procedure, you must set the CommandType of the Command object to StoredProcedure.
The following code example shows how to execute a stored procedure on a Sybase database and read the results using a DataReader. The example uses the emp table (see "Sample Tables for Sybase"). The Sybase database in this example does not require the Database connection string option.
Create the following stored procedure:
CREATE PROCEDURE GetEmpSalary (@empno int, @sal char(7) output) AS SELECT @sal = sal FROM emp WHERE empno = @empnoThe following code example executes the GetEmpSalary stored procedure:
// Open connection to SequeLink Server on Sybase database SybaseConnection Conn; Conn = new SequeLinkConnection("host=bowhead;port=19996;User ID=test01; Password=test01"); Conn.Open(); // Make a command object for the stored procedure // You must set the CommandType of the Command object // to StoredProcedure SequeLinkCommand DBCmd = new SequeLinkCommand("GetEmpSalary",Conn); DBCmd.CommandType = CommandType.StoredProcedure; SequeLinkDataReader myDataReader; try { myDataReader = myCommand.ExecuteReader() myDataReader.Close(); } catch (Exception ex) { // Display any exceptions in a messagebox MessageBox.Show (ex.Message); } // Close the connection Conn.Close();